home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 May / CMCD0505.ISO / Software / Demo / DesktopX / objects / ktekdockv1.dxpack / {D37D3FE7-CE19-4EA8-8D28-90948A76F778}.DXScript2 < prev    next >
Extensible Markup Language  |  2004-08-24  |  10KB  |  315 lines

  1. <?xml version="1.0"?>
  2. <!--DXScript Data File.  Version 2.0-->
  3. <DXScript>
  4.     <Script><![CDATA[Dim weatherdata,weatherdataImp
  5. 'Called when the script is executed
  6. Sub Object_OnScriptEnter    
  7.     'Object.SetTimer 6001, 600000
  8.     'Object_OnTimer6001
  9. End Sub
  10.  
  11. 'Called when the script is terminated
  12. Sub Object_OnScriptExit
  13.  
  14. End Sub
  15.  
  16. Sub Object_OnTimer6001
  17.     If System.InternetConnected Then
  18.         On Error Resume Next
  19.         ' Create a web object
  20.         Set http = CreateObject("Microsoft.XmlHttp")
  21.         ' Retrieve data
  22.         Randomize
  23.         str_RANDOM_URL = "&rnd=" & rnd()
  24.         
  25.         str_UNITS = "&unit=m"
  26.         http.Open "GET", "http://xoap.weather.com/weather/local/" & Object.PersistStorage("zipcode") & "?cc=*&dayf=5" & str_UNITS & str_RANDOM_URL, False
  27.         http.send ""
  28.         weatherdata = http.responseText
  29.         str_RANDOM_URL = "&rnd=" & rnd()
  30.         str_UNITS = "&unit=s"
  31.         http.Open "GET", "http://xoap.weather.com/weather/local/" & Object.PersistStorage("zipcode") & "?cc=*&dayf=5" & str_UNITS & str_RANDOM_URL, False
  32.         http.send ""
  33.         weatherdataImp = http.responseText
  34.         
  35.         If weatherdata <> "" Then
  36.             weathertemp = xmlstripper("<dnam>", weatherdata)
  37.             If weathertemp = "" Then
  38.                 Msgbox "This doesn't appear to be a valid zip code." & vbNewLine & vbNewLine & "Please try again.", vbExclamation + vbOKOnly, "Zip error ..."
  39.                 x = InputBox("Please enter the zip code or location that you would like to display the weather for:" & vbNewLine & "e.g. 48152 or Hastings,England", "Select location ...", "48152")
  40.         
  41.                 Object.PersistStorage("zipcode") = x
  42.                 Object_OnTimer6001
  43.                 Exit Sub    
  44.             Else
  45.                 If IsNumeric(Object.PersistStorage("zipcode")) Then weathertemp = Left(weathertemp, InStr(weathertemp, "(")-2)
  46.                 DesktopX.ScriptObject("kdockweatherlocation").Object.Text = weathertemp
  47.                 Object.PersistStorage("status") = weathertemp
  48.             End If
  49.             
  50.             'temperature
  51.             showtemp
  52.             'DesktopX.ScriptObject("kdockweathertemp").Object.Text = xmlstripper("<tmp>", weatherdata) & TempUnits
  53.             
  54.             ' weather condition text and icon
  55.             conditions = xmlstripper("<cc>", weatherdata)
  56.             conditions = xmlstripper("<t>", conditions)
  57.             DesktopX.ScriptObject("kdockweatherconditions").Object.Text = conditions
  58.             icon = xmlstripper("<icon>", weatherdata)
  59.             Object.PersistStorage("Conditions") = icon
  60.             Object.State = pickicon(icon)
  61.             
  62.             'humidity
  63.             If IsNumeric(xmlstripper("<hmid>", weatherdata)) Then
  64.                 Object.PersistStorage("Humidity") = xmlstripper("<hmid>", weatherdata) & "%"
  65.             Else
  66.                 Object.PersistStorage("Humidity") = xmlstripper("<hmid>", weatherdata)
  67.             End If
  68.             DesktopX.ScriptObject("kdockweatherhumidity").Object.Text = "Humidity: " & Object.PersistStorage("Humidity")
  69.             
  70.             ' wind stuff
  71.             showwind
  72.             
  73.             
  74.             'sunrise and sunset 
  75.             DesktopX.Object("kdockweathersunrise").Text = "Sunrise: " & xmlstripper("<sunr>", weatherdata)
  76.             DesktopX.Object("kdockweathersunset").Text = "Sunset: " & xmlstripper("<suns>", weatherdata)
  77.             
  78.             ' Clear variables for clean code and skip the forecast
  79.             Set http = nothing
  80.             'Set weatherdata = Nothing
  81.             Set weathertemp = Nothing
  82.             Set forecastdatastart = Nothing
  83.             Set forecastdataend = Nothing
  84.             Exit Sub
  85.             
  86.             'forecast stuff
  87.             weathertemp = xmlstripper("<dayf>", weatherdata)
  88.             For x = 1 To 5
  89.                 DesktopX.Object("weather_image_fc" & x).State = selecticon(xmlstripper("<icon>", weathertemp))
  90.                 daytemp = InStr(weathertemp, "t=") + 3
  91.                 daytemp2 = InStr(weathertemp, "dt=") - 2
  92.                 daytemp3 = Mid(weathertemp, daytemp, 3)
  93.                 daytemp4 = Mid(weathertemp, daytemp, daytemp2 - daytemp)    
  94.                 ' forecast temperature
  95.                 theTemp=xmlstripper("<hi>", weathertemp)    
  96.                 If IsNumeric(theTemp) Then    
  97.                     If theTemp<100 Then
  98.                         If str_UNITS = "&unit=s" Then
  99.                             theTemp = theTemp & Chr(176) & "F"
  100.                         Else
  101.                             theTemp = theTemp & Chr(176) & "C"
  102.                         End If    
  103.                     End If
  104.                 End If
  105.                 Object.PersistStorage("ForecastTemp" & x)=theTemp
  106.                 
  107.                 'more stuff
  108.                 Object.PersistStorage("ForecastDay" & x) = daytemp3
  109.                 Object.PersistStorage("ForecastLongDay" & x) = daytemp4
  110.                 conditions=": "&xmlstripper("<t>", weathertemp)
  111.                 
  112.                 weathertempW=xmlstripper("<wind>", weathertemp)
  113.                 wind=xmlstripper("<t>", weathertempW)
  114.                 If wind<>"CALM" Then
  115.                     wind="; "&wind&" ("&xmlstripper("<s>", weathertempW)& WindUnits    &")"
  116.                 Else
  117.                     wind="; "&wind
  118.                 End If
  119.                 
  120.                 chanceofrain="; "&xmlstripper("<ppcp>", weathertemp)&"% chance rain"
  121.                 
  122.                 weathertemp = right(weathertemp, Len(weathertemp) - InStr(weathertemp, "/day"))
  123.                 DesktopX.ScriptObject("weather_daytemp" & x).Object.Text = Object.PersistStorage("ForecastTemp" & x)
  124.                 'DesktopX.ScriptObject("weather_day" & x).Object.State = Object.PersistStorage("ForecastDay" & x)        
  125.                 
  126.                 Object.PersistStorage("ForecastSummary" & x) = daytemp3 & conditions & wind & chanceofrain
  127.                         
  128.                 Set daytemp = Nothing
  129.                 Set daytemp2 = Nothing
  130.                 Set daytemp3 = Nothing
  131.                 Set daytemp4 = Nothing
  132.                 Set conditions = Nothing
  133.                 Set icon = Nothing
  134.                 Set weathertempW = Nothing
  135.             Next
  136.         End If
  137.         
  138.         ' Clear variables for clean code
  139.         Set http = nothing
  140.         Set weatherdata = Nothing
  141.         Set weathertemp = Nothing
  142.         Set forecastdatastart = Nothing
  143.         Set forecastdataend = Nothing
  144.     End If
  145. End Sub
  146.  
  147. Sub showtemp
  148.     If Object.PersistStorage("t_units") = "metric" Then
  149.         TempUnits = Chr(176) & "C"
  150.         thedata=weatherdata
  151.     Else
  152.         TempUnits = Chr(176) & "F"
  153.         thedata=weatherdataImp
  154.     End If
  155.     DesktopX.ScriptObject("kdockweathertemp").Object.Text = xmlstripper("<tmp>", thedata) & TempUnits
  156. End Sub
  157.  
  158. Sub showwind
  159.     If Object.PersistStorage("w_units") = "metric" Then
  160.         WindUnits = "kmh"
  161.         thedata=weatherdata
  162.     Else
  163.         WindUnits = "mph"
  164.         thedata=weatherdataImp
  165.     End If
  166.     weathertemp = xmlstripper("<wind>", thedata)
  167.     windspeed=xmlstripper("<s>", weathertemp)
  168.     windang=xmlstripper("<t>", weathertemp)
  169.     If windspeed = "calm" Then
  170.         DesktopX.Object("kdockweathervane").rotation=0
  171.         DesktopX.Object("kdockweathervane").State = "calm"
  172.         windtext=windspeed    
  173.     Else
  174.         If windang = "VAR" Then
  175.             DesktopX.Object("kdockweathervane").rotation=0
  176.             DesktopX.Object("kdockweathervane").State = "var"
  177.         Else
  178.             DesktopX.Object("kdockweathervane").State = "arrow"
  179.             DesktopX.Object("kdockweathervane").rotation=windangle(windang)
  180.         End If
  181.         windtext = windang & Chr(13) & windspeed & " " & WindUnits                
  182.     End If
  183.     DesktopX.ScriptObject("kdockweathervanetext").Object.Text = windtext
  184. End Sub
  185.  
  186. Function xmlstripper(param, string)
  187.     datastart = InStr(string, param) + Len(param)
  188.     datalength = Instr(string, "</" & Right(param, Len(param) - 1)) - datastart
  189.     xmlstripper = Mid(string, datastart, datalength)
  190. End Function
  191.  
  192. Function windangle(direction)'of course I got all these angles wrong, but fixed it by making the arrow point south ;)
  193.     Select Case direction
  194.         Case "N"
  195.             windangle=0
  196.         Case "NNE"
  197.             windangle=22
  198.         Case "NE"
  199.             windangle=45
  200.         Case "ENE"
  201.             windangle=67
  202.         Case "E"
  203.             windangle=90
  204.         Case "ESE"
  205.             windangle=112
  206.         Case "SE"
  207.             windangle=135
  208.         Case "SSE"
  209.             windangle=157
  210.         Case "S"
  211.             windangle=180
  212.         Case "SSW"
  213.             windangle=202
  214.         Case "SW"
  215.             windangle=225
  216.         Case "WSW"
  217.             windangle=247
  218.         Case "W"
  219.             windangle=270
  220.         Case "WNW"
  221.             windangle=292
  222.         Case "NW"
  223.             windangle=315
  224.         Case "NNW"
  225.             windangle=337
  226.     End Select
  227. End Function
  228.  
  229. Function pickicon(conditions)
  230.     Select Case conditions    
  231.         Case 25,31
  232.             pickicon = "finenight"
  233.         Case 29,33
  234.             pickicon = "partlycloudynight"
  235.         Case 27
  236.             pickicon = "mostlycloudynight"
  237.         Case 45
  238.             pickicon = "scatteredrainnight"
  239.         Case 47
  240.             pickicon = "scatteredthundernight"
  241.         Case 46
  242.             pickicon = "scatteredsnownight"
  243.             
  244.         Case 37
  245.             pickicon="scatteredthunder"
  246.         Case 39
  247.             pickicon = "scatteredrain"
  248.         Case 28    
  249.             pickicon = "mostlycloudy"    
  250.         Case 23,24,32,36
  251.             pickicon = "fine"
  252.         Case 19,20,21,22
  253.             pickicon = "foggy"
  254.         Case 30,34,44
  255.             pickicon = "partlycloudy"
  256.         Case 26
  257.             pickicon = "cloudy"
  258.         Case 8,9,11
  259.             pickicon = "lightrain"
  260.         Case 1,2,10,12,40
  261.             pickicon = "heavyrain"
  262.         Case 5,6,7,18
  263.             pickicon = "snowymix"
  264.         Case 13,14,15,16, 41,42,43
  265.             pickicon = "snow"
  266.         Case 0,3,4,17,35,38
  267.             pickicon = "thunder"
  268.         Case "na"
  269.             pickicon = "unknown"
  270.     End Select
  271. End Function
  272.  
  273.  
  274. Function selecticon(conditions)
  275.     Select Case conditions
  276.     
  277.         Case 25,31
  278.             selecticon = "moon"
  279.         Case 29,33
  280.             selecticon = "moonpartlycloudy"
  281.         Case 27
  282.             selecticon = "moonmostlycloudy"
  283.         Case 45
  284.             selecticon = "moonscatteredrain"
  285.         Case 47
  286.             selecticon = "moonscatteredthunder"
  287.         Case 46
  288.             selecticon = "moonscatteredsnow"
  289.         
  290.         Case 9,11,39
  291.             selecticon = "scatteredrain"
  292.         Case 28    
  293.             selecticon = "mostlycloudy"
  294.             
  295.         Case 23,24,32,34,36
  296.             selecticon = "sunny"
  297.         Case 19,20,21,22
  298.             selecticon = "foggy"
  299.         Case 30,44
  300.             selecticon = "partlycloudy"
  301.         Case 26
  302.             selecticon = "cloudy"
  303.         Case 1,2,12,40
  304.             selecticon = "rain"
  305.         Case 5,6,7,8,10,18
  306.             selecticon = "sleet"
  307.         Case 13,14,15,16, 41,42,43
  308.             selecticon = "snow"
  309.         Case 0,3,4,17,35,37,38
  310.             selecticon = "thunder"
  311.         Case "na"
  312.             selecticon = "unknown"
  313.     End Select
  314. End Function]]></Script><Globals><Editor><PropPane>0</PropPane><EditorLeft>199</EditorLeft><EditorTop>7</EditorTop><EditorRight>1254</EditorRight><EditorBottom>840</EditorBottom></Editor><Object><LanguageCLSID>{B54F3741-5B07-11CF-A4B0-00AA004A55E8}</LanguageCLSID><ControlCLSID>{00000000-0000-0000-0000-000000000000}</ControlCLSID><ControlObjWidth>64</ControlObjWidth><ControlObjHeight>64</ControlObjHeight><RunState>1</RunState><ManualControlLoad>0</ManualControlLoad><ScriptHostVersion>2</ScriptHostVersion></Object></Globals></DXScript>
  315.